using Weapons.Components.ComponentData;
using Weapons.Components.ComponentData.AttackData;

namespace Weapons.Components
{
    public class WeaponMovement : WeaponComponent<MovementData, AttackMove>
    {
        private Movement coreMovement;
        private Movement CoreMovement => coreMovement ? coreMovement : Core.GetCoreComponent<Movement>();

        //protected override void Awake()
        //{
        //    base.Awake();

        //    data = newWeapon.Data.GetData<MovementData>();
        //}

        protected override void Start()
        {
            base.Start();


            //�������ʱ��������
            if (eventHandler != null)
            {
                eventHandler.OnStartMovement += HandleStartMovement;
                eventHandler.OnStopMovement += HandleStopMovement;
            }
        }

        protected override void OnDestroy()
        {
            base.OnDestroy();
            eventHandler.OnStopMovement -= HandleStopMovement;
            eventHandler.OnStartMovement -= HandleStartMovement;
        }


        //private Movement CoreMovement => coreMovement ? coreMovement : Core.GetComponent(ref coreMovement);
        //���ϴ����ǲ���������Դ���룬ֱ��ʹ�õĻ��ᱨ���²���֮ǰû�и��ϵ�Ե��

        //private MovementData data;

        private void HandleStartMovement()
        {
            //var currentAttackData = data.AttactData[newWeapon.CurrentAttackCounter];

            CoreMovement.SetVelocity(currentAttackData.Velocity, currentAttackData.Direction,
                CoreMovement.FacingDirection);
        }

        private void HandleStopMovement()
        {
            CoreMovement.SetVelocityZero();
        }
    }
}